package com.changfeng.handler.response.vo;

import com.changfeng.exception.ChangFengException;
import com.changfeng.exception.ChangFengExceptionEnum;
import com.changfeng.exception.ServiceExceptionEnum;

public class ResponseVO<M> {

    private int status;

    private String msg;

    private M data;

    private ResponseVO() {

    }

    public static<M> ResponseVO forEnum(ServiceExceptionEnum exceptionEnum) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setStatus(exceptionEnum.getCode());
        responseVO.setMsg(exceptionEnum.getMessage());

        return responseVO;
    }

    public static<M> ResponseVO forException(ChangFengException exception) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setStatus(exception.getCode());
        responseVO.setMsg(exception.getMessage());

        return responseVO;
    }


    public static<M> ResponseVO success(M m) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setStatus(ChangFengExceptionEnum.OK.getCode());
        responseVO.setData(m);
        return responseVO;
    }

    public static<M> ResponseVO success(String msg) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setStatus(0);
        responseVO.setMsg(msg);

        return responseVO;
    }

    public static<M> ResponseVO serviceFail(String msg) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setStatus(1);
        responseVO.setMsg(msg);

        return responseVO;
    }

    public static<M> ResponseVO appFail(String msg) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setStatus(ChangFengExceptionEnum.ERROR.getCode());
        responseVO.setMsg(msg);

        return responseVO;
    }

    public static<M> ResponseVO appFail() {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setStatus(ChangFengExceptionEnum.ERROR.getCode());
        responseVO.setMsg(ChangFengExceptionEnum.ERROR.getMessage());

        return responseVO;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public M getData() {
        return data;
    }

    public void setData(M data) {
        this.data = data;
    }
}